//
//  WYShareBottomView.m
//  Boss
//
//  Created by admin on 2018/7/23.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYShareBottomView.h"
#import "WXApi.h"

//#import  <TencentOpenAPI/QQApi.h>

#import <TencentOpenAPI/QQApiInterface.h>
@implementation WYShareBottomView
+(instancetype)shareedShareBottomView
{
    return [[NSBundle mainBundle] loadNibNamed:@"WYShareBottomView" owner:nil options:nil].firstObject;
}
-(void)setBottomHeightStr:(NSString *)bottomHeightStr
{
    _bottomHeightStr = bottomHeightStr;
    if (kDevice_Is_iPhoneX) {
        self.bottomHeight.constant = 44+50;
        self.bottomBottomHeight.constant = 50;
        self.bottomViewHeight.constant = 44;
    }
    
    
    
}
- (IBAction)weChatShare:(id)sender {
    [self cancelAction:nil];
    
    if (self.wait) {
        if (self.complete) {
            self.complete(0);
        }
        
        return;
    }
    
    SendMessageToWXReq *req1 = [[SendMessageToWXReq alloc]init];
    
    // 是否是文档
    req1.bText =  NO;
    
    //    WXSceneSession  = 0,        /**< 聊天界面    */
    //    WXSceneTimeline = 1,        /**< 朋友圈      */
    //    WXSceneFavorite = 2,
    
    
    req1.scene = WXSceneSession;
    
    //创建分享内容对象
    WXMediaMessage *urlMessage = [WXMediaMessage message];
    urlMessage.title = self.kLinkTitle;//分享标题
    urlMessage.description = self.kLinkDescription;//分享描述
    [urlMessage setThumbImage:self.shareImage];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
    
    //创建多媒体对象
    WXWebpageObject *webObj = [WXWebpageObject object];
    webObj.webpageUrl = self.kLinkURL;//分享链接
    
    //完成发送对象实例
    urlMessage.mediaObject = webObj;
    req1.message = urlMessage;
    
    //发送分享信息
    [WXApi sendReq:req1];
}
- (IBAction)friendShatre:(id)sender {
     [self cancelAction:nil];
    
    if (self.wait) {
        if (self.complete) {
            self.complete(1);
        }
        return;
    }
   
    SendMessageToWXReq *req1 = [[SendMessageToWXReq alloc]init];
    
    // 是否是文档
    req1.bText =  NO;
    
    //    WXSceneSession  = 0,        /**< 聊天界面    */
    //    WXSceneTimeline = 1,        /**< 朋友圈      */
    //    WXSceneFavorite = 2,
    
    
    req1.scene = WXSceneTimeline;
    
    //创建分享内容对象
    WXMediaMessage *urlMessage = [WXMediaMessage message];
    urlMessage.title = self.kLinkTitle;//分享标题
    urlMessage.description = self.kLinkDescription;//分享描述
    [urlMessage setThumbImage:self.shareImage];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
    
    //创建多媒体对象
    WXWebpageObject *webObj = [WXWebpageObject object];
    webObj.webpageUrl = self.kLinkURL;//分享链接
    
    //完成发送对象实例
    urlMessage.mediaObject = webObj;
    req1.message = urlMessage;
    
    //发送分享信息
    [WXApi sendReq:req1];
    
    
    
}
- (IBAction)qqShare:(id)sender {
      [self cancelAction:nil];
  
    if (self.wait) {
        if (self.complete) {
            self.complete(2);
        }
        return;
    }
  
    
    NSData *data = UIImagePNGRepresentation(self.shareImage);
    
    QQApiURLObject *urlObj = [QQApiURLObject objectWithURL:[NSURL URLWithString:self.kLinkURL] title:self.kLinkTitle description:self.kLinkDescription previewImageData:data targetContentType:(QQApiURLTargetTypeNews)];
//
//    QQApiImageObject *imgObj = [QQApiImageObject objectWithData:nil previewImageData:data title:self.kLinkTitle description:self.kLinkDescription];
    
    
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:urlObj];
    
    //将内容分享到qq
    
    QQApiSendResultCode sent = [QQApiInterface sendReq:req];
    [self handleSendResult:sent];
    NSLog(@"%d",sent);
    
}
- (IBAction)QQZoneShare:(id)sender {
     [self cancelAction:nil];
    
    if (self.wait) {
        if (self.complete) {
            self.complete(3);
        }
        return;
    }
   
    NSData *data = UIImagePNGRepresentation(self.shareImage);
    
    QQApiURLObject *urlObj = [QQApiURLObject objectWithURL:[NSURL URLWithString:self.kLinkURL] title:self.kLinkTitle description:self.kLinkDescription previewImageData:data targetContentType:(QQApiURLTargetTypeNews)];
    //
    //    QQApiImageObject *imgObj = [QQApiImageObject objectWithData:nil previewImageData:data title:self.kLinkTitle description:self.kLinkDescription];
    
    
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:urlObj];
    
    //将内容分享到qq
    
    QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req];
    [self handleSendResult:sent];
    
    
    
}
- (IBAction)weiBoShare:(id)sender {
    [self cancelAction:nil];
//
//    if (self.wait) {
//        if (self.complete) {
//            self.complete(4);
//        }
//        return;
//    }
//
//    WBMessageObject *message = [WBMessageObject message];
//
//
////    WBWebpageObject *webpage = [WBWebpageObject object];
////    webpage.objectID = @"identifier1";
////    webpage.title = self.kLinkTitle;
////    webpage.description = self.kLinkDescription;
////     //NSData *data = UIImagePNGRepresentation(self.shareImage);
////    NSData *data = UIImageJPEGRepresentation(self.shareImage, 0.1);
////    webpage.thumbnailData = data;
////    webpage.webpageUrl = self.kLinkURL;
////    message.mediaObject = webpage;
//
//    WBImageObject * imageObject = [WBImageObject object];
//    imageObject.imageData = UIImageJPEGRepresentation(self.shareImage, 1.0);
//
//    message.text = [NSString stringWithFormat:@"%@  %@",self.kLinkDescription,self.kLinkURL];                                  // 分享文字： 内容 + Url地址
//    message.imageObject = imageObject;     // 配置分享图片
//
//
//    WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message];
//    [WeiboSDK sendRequest:request];
}
- (IBAction)cancelAction:(id)sender {
    self.frame = CGRectMake(0, kScreenHeight, kScreenWidth, 200);
}
- (void)handleSendResult:(QQApiSendResultCode)sendResult
{
    switch (sendResult)
    {
            
        case EQQAPIAPPNOTREGISTED:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            
            break;
        }
        case EQQAPIMESSAGECONTENTINVALID:
        case EQQAPIMESSAGECONTENTNULL:
        case EQQAPIMESSAGETYPEINVALID:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            
            break;
        }
        case EQQAPIQQNOTINSTALLED:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的设备未安装手机QQ" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            
            break;
        }
        case EQQAPIQQNOTSUPPORTAPI:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的设备未安装手机QQ" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            
            break;
        }
        case EQQAPISENDFAILD:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            
            break;
        }
        case EQQAPIVERSIONNEEDUPDATE:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前QQ版本太低，需要更新" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            break;
        }
        default:
        {
            break;
        }
    }
}

@end
